package com.wgy.day42Jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

/**
 * Created by pc on 2021/1/11 20:58
 * Description: LearningJava
 */
/*Jsoup选择器查询*/
public class JsoupDemo5 {
    public static void main(String[] args) throws IOException {
        //1.获取student.xml的path
        // String path = JsoupDemo3.class.getClassLoader().getResource("student.xml").getPath();
        //2.获取document对象
        Document document = Jsoup.parse(new File("student.xml"), "utf-8");
        //3.查询所有name标签
        Elements elements = document.select("name");
        System.out.println(elements);
        System.out.println("==============");
        //4.查询id值为1的元素
        Elements elements1 = document.select("#1");
        System.out.println(elements1);
        System.out.println("==============");

        //5.获取student标签下的number为heima_0001的age子标签
         //5.1获取student标签下的number为heima_0001
        Elements elements2 = document.select("student[number=\"heima_0001\"]");
        System.out.println(elements2);
       //5.2获取student标签下的number为heima_0001age子标签
        Elements elements3 = document.select("student[number=\"heima_0001\"] > age");
        System.out.println(elements3);
    }
}
